﻿namespace com.stifel.ServerBuildMgmt
{
    //http://www.codetoblog.com/2010/06/unit-testing-windows-workflow_04.html
    //http://www.codetoblog.com/2010_06_01_archive.html
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Net.Mail;
    using System.Threading;
    using System.Workflow.Activities;
    using System.Workflow.Runtime;
    using System.Workflow.Runtime.Hosting;

    using com.stifel.ServerBuildMgmtDao;
    using com.stifel.SharePoint;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Workflow;

    public sealed partial class RequestStatusWorkflow : SequentialWorkflowActivity
    {
        #region Fields

        public Guid workflowId = default( System.Guid );
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties( );

        StifelVirtualServerRequestConfiguration _configuration;

        #endregion Fields

        #region Constructors

        public RequestStatusWorkflow( )
        {
            InitializeComponent( );
        }

        #endregion Constructors

        #region Properties

        public StifelVirtualServerRequest CurrentRequest
        {
            get;
            set;
        }

        public SPUserInfoExpanded CurrentUser
        {
            get;
            set;
        }

        public SPWeb CurrentWeb
        {
            get;
            set;
        }

        StifelVirtualServerRequestConfiguration configuration
        {
            get
            {
                if ( _configuration == null )
                {
                    StifelVirtualServerRequestConfigurationDao dao = new StifelVirtualServerRequestConfigurationDao( CurrentWeb.Url );
                    _configuration = dao.Get( );
                }
                return _configuration;
            }
        }
        protected class Parms
        {
            public StifelVirtualServerRequest Request
            {
                get;
                set;
            }
            public SPWeb Web
            {
                get;
                set;
            }
            public SPUserInfoExpanded User
            {
                get;
                set;
            }
        }
        #endregion Properties

        #region Methods

        public static void Start( StifelVirtualServerRequest value, SPWeb spWeb, SPUserInfoExpanded user )
        {
            Dictionary<string, object> parameters = new Dictionary<string, object>( );
            parameters.Add( "CurrentRequest", value );
            parameters.Add( "CurrentUser", user );
            parameters.Add( "CurrentWeb", spWeb );
            ManualWorkflowSchedulerService service = new ManualWorkflowSchedulerService( );
            WorkflowRuntime runtime = new WorkflowRuntime( );
            runtime.AddService( service );
            WorkflowInstance instance = runtime.CreateWorkflow( typeof( RequestStatusWorkflow ), parameters );
            instance.Start( );
            var scheduler = runtime.GetService<ManualWorkflowSchedulerService>( );
            scheduler.RunWorkflow( instance.InstanceId );
        }

        private void ADConfigAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.ADConfigNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.AD, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.AD, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.AD, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AD.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.ADSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.ADSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.ADNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.ADSiteURLUrl ) );
                }
                CurrentRequest.ADConfigNotificationDate = DateTime.Now;

                // optionally send email
                if ( overrideConfiguration || ( configuration.ADSendEmail.HasValue && configuration.ADSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.AD, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void ADConfigCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceADConfigStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AD.Completed );
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AD.Finalized );
                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.ADNotificationId != null )
                    removeNotification( configuration.ADSiteURLUrl, notificationId.ADNotificationId );
                // clear notification
                notificationId.ADNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                // update
                CurrentRequest.RequestCompleted = CurrentRequest.IsConfigCompleted( );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void ADConfigStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AD.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        Guid addNotification( string title, string notification, string pageurl, string siteurl )
        {
            Guid uniqueId = Guid.Empty;
            if ( StifelNotificationDao.ListExists( siteurl ) )
            {
                StifelNotification value = new StifelNotification
                {
                    Notification = notification,
                    NotificationURL = pageurl,
                    RequestIdentifier = CurrentRequest.Id,
                    RequestUniqueId = CurrentRequest.UniqueId,
                    Title = title
                };
                StifelNotificationDao dao = new StifelNotificationDao( siteurl );
                uniqueId = dao.Add( value );
            }
            return uniqueId;
        }

        private void approvalAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.ApprovalNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.Approval, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Approval, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Approval, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Approval.Available );

                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.ApprovalSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.ApprovalSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.ApprovalNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.ApprovalSiteURLUrl ) );
                }

                CurrentRequest.ApprovalNotificationDate = DateTime.Now;

                // optionally send email
                if ( overrideConfiguration || ( configuration.ApprovalSendEmail.HasValue && configuration.ApprovalSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.Approval, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }

                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.PendingApproval;

                // update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void approvalCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceApprovalStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Approval.Completed );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void approvalStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Approval.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        private void approvedStateInError_ExecuteCode( object sender, EventArgs e )
        {
        }

        private void AVConfigAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.AVConfigNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.AV, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.AV, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.AV, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AV.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.AVSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.AVSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.AVNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.AVSiteURLUrl ) );
                }
                CurrentRequest.AVConfigNotificationDate = DateTime.Now;

                // optionally send email
                if ( overrideConfiguration || ( configuration.AVSendEmail.HasValue && configuration.AVSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.AV, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void AVConfigCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceAVConfigStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AV.Completed );

                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AV.Finalized );
                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.AVNotificationId != null )
                    removeNotification( configuration.AVSiteURLUrl, notificationId.AVNotificationId );
                // clear notification
                notificationId.AVNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );

                // update
                CurrentRequest.RequestCompleted = CurrentRequest.IsConfigCompleted( );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void AVConfigStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.AV.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        private void backupConfigAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.BackupConfigNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.Backup, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Backup, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Backup, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.BackUp.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.BackupSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.BackupSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.BackupNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.BackupSiteURLUrl ) );
                }
                CurrentRequest.BackupConfigNotificationDate = DateTime.Now;

                // optionally send email
                if ( overrideConfiguration || ( configuration.BackupSendEmail.HasValue && configuration.BackupSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.Backup, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void backupConfigCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceBackupConfigStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.BackUp.Completed );
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.BackUp.Finalized );
                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.BackupNotificationId != null )
                    removeNotification( configuration.BackupSiteURLUrl, notificationId.BackupNotificationId );
                // clear notification
                notificationId.BackupNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                // update
                CurrentRequest.RequestCompleted = CurrentRequest.IsConfigCompleted( );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void backupConfigStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.BackUp.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        private void buildAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.BuildNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.Build, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Build, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Build, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Build.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.BuildSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.BuildSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.BuildNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.BuildSiteURLUrl ) );
                }
                CurrentRequest.BuildNotificationDate = DateTime.Now;

                // optionally send email
                if ( overrideConfiguration || ( configuration.BuildSendEmail.HasValue && configuration.BuildSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.Build, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void buildCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceBuildStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Build.Completed );

                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Build.Finalized );

                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.BuildNotificationId != null )
                    removeNotification( configuration.BuildSiteURLUrl, notificationId.BuildNotificationId );
                // clear notification
                notificationId.BuildNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void buildStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Build.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        /// <summary>
        /// Error handling
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void codeActivity1_ExecuteCode( object sender, EventArgs e )
        {
            string s = "error";
            string t = s;
        }

        private void codeActivity1_ExecuteCode_1( object sender, EventArgs e )
        {
        }

        private void codeActivity2_ExecuteCode( object sender, EventArgs e )
        {
            StifelVirtualServerRequest r = CurrentRequest;
            string s = "xxx";
        }

        private void initialRequestStateInError_ExecuteCode( object sender, EventArgs e )
        {
        }

        private void isADConfigAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsADConfigAvailable( );
        }

        private void isADConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsADConfigCompleted( );
        }

        private void isADConfigFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsADConfigFinalized( );
        }

        private void isADConfigStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsADConfigStarted( );
        }

        private void isApprovalAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsApprovalAvailable( );
        }

        private void isApprovalCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsApprovalCompleted( );
        }

        private void isApprovalFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsApprovalFinalized( );
        }

        private void isApprovalStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsApprovalStarted( );
        }

        private void isAVConfigAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsAVConfigAvailable( );
        }

        private void isAVConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsAVConfigCompleted( );
        }

        private void isAVConfigFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsAVConfigFinalized( );
        }

        private void isAVConfigStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsAVConfigStarted( );
        }

        private void isBackupConfigAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBackupConfigAvailable( );
        }

        private void isBackupConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBackupConfigCompleted( );
        }

        private void isBackupConfigFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBackupConfigFinalized( );
        }

        private void isBackupConfigStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBackupConfigStarted( );
        }

        private void isBuildAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBuildAvailable( );
        }

        private void isBuildCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBuildCompleted( );
        }

        private void isBuildFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBuildFinalized( );
        }

        private void isBuildStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsBuildStarted( );
        }

        private void isConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsConfigCompleted( );
        }

        private void isInApprovalState( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsInApprovalState( );
        }

        private void isInBuildState( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsInBuildState( );
        }

        private void isInInitialRequestState( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsInInitialRequestState( );
        }

        private void isInPostBuildState( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsInPostBuildState( );
        }

        private void isMonitoringConfigAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsMonitoringConfigAvailable( );
        }

        private void isMonitoringConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsMonitoringConfigCompleted( );
        }

        private void isMonitoringConfigFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsMonitoringConfigFinalized( );
        }

        private void isMonitoringConfigStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsMonitoringConfigStarted( );
        }

        private void isPatchConfigAvailable( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsPatchConfigAvailable( );
        }

        private void isPatchConfigCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsPatchConfigCompleted( );
        }

        private void isPatchConfigFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsPatchConfigFinalized( );
        }

        private void isPatchConfigStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsPatchConfigStarted( );
        }

        private void isRequestApproved( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.RequestApproved.HasValue ? CurrentRequest.RequestApproved.Value : false;
        }

        private void isRequestCanceled( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.RequestCanceled.HasValue ? CurrentRequest.RequestCanceled.Value : false;
        }

        private void isRequestCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.RequestCompleted.HasValue ? CurrentRequest.RequestCompleted.Value : false;
        }

        private void isRequestorCompleted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsRequestorCompleted( );
        }

        private void isRequestorFinalized( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsRequestorFinalized( );
        }

        private void isRequestorStarted( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.IsRequestorStarted( );
        }

        private void isRequestRejected( object sender, ConditionalEventArgs e )
        {
            e.Result = CurrentRequest.RequestRejected.HasValue ? CurrentRequest.RequestRejected.Value : false;
        }

        private void monitorConfigAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.MonitorConfigNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.Monitor, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Monitor, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Monitor, CurrentRequest.Id, CurrentRequest.UniqueId );

                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Network.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.MonitorSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.MonitorSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.MonitorNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.MonitorSiteURLUrl ) );
                }
                CurrentRequest.MonitorConfigNotificationDate = DateTime.Now;
                // optionally send email
                if ( overrideConfiguration || ( configuration.MonitorSendEmail.HasValue && configuration.MonitorSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.Monitor, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void monitorConfigCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceMonitoringConfigStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Network.Completed );
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Network.Finalized );
                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.MonitorNotificationId != null )
                    removeNotification( configuration.MonitorSiteURLUrl, notificationId.MonitorNotificationId );
                // clear notification
                notificationId.MonitorNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                // update
                CurrentRequest.RequestCompleted = CurrentRequest.IsConfigCompleted( );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void monitorConfigStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Network.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        private void onWorkflowActivated_Invoked( object sender, ExternalDataEventArgs e )
        {
            string s = "invoked";
            string t = s;
        }

        private void patchConfigAvailable_ExecuteCode( object sender, EventArgs e )
        {
            if ( !CurrentRequest.PatchConfigNotificationDate.HasValue )
            {
                string pageUrl = configuration.FormatPageUrl( StifelVirtualServerRequestConfiguration.Area.Patch, CurrentRequest.UniqueId );
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Patch, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Patch, CurrentRequest.Id, CurrentRequest.UniqueId );
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Patch.Available );
                // add notification
                bool overrideConfiguration = false;
                if ( StifelNotificationDao.ListExists( configuration.PatchSiteURLUrl ) )
                {
                    Guid uniqueId = addNotification( title, notification, pageUrl, configuration.PatchSiteURLUrl );
                    NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                    notificationId.PatchNotificationId = uniqueId;
                    CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                }
                else
                {
                    overrideConfiguration = true;
                    CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.GeneralError.ERROR_NONOTIFICATIONLISTFOUND( configuration.PatchSiteURLUrl ) );
                }
                CurrentRequest.PatchConfigNotificationDate = DateTime.Now;
                // optionally send email
                if ( overrideConfiguration || ( configuration.PatchSendEmail.HasValue && configuration.PatchSendEmail.Value ) )
                {
                    List<MailAddress> to = configuration.GetSecurityGroupEmailAddresses( StifelVirtualServerRequestConfiguration.Area.Patch, CurrentWeb.Url );

                    if ( to.Count > 0 )
                    {
                        SPSendEmail spSendEmail = new SPSendEmail( );
                        bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, to );
                        if ( !ok )
                            CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                    }
                }
                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Inprogress;

                //Update
                updateRequestButNoTriggerWorkflow( CurrentRequest );
            }
        }

        private void patchConfigCompleted_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvancePatchConfigStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Patch.Completed );
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Patch.Finalized );
                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;
                // remove notification
                if ( notificationId.PatchNotificationId != null )
                    removeNotification( configuration.PatchSiteURLUrl, notificationId.PatchNotificationId );
                // clear notification
                notificationId.PatchNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
                // update
                CurrentRequest.RequestCompleted = CurrentRequest.IsConfigCompleted( );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        private void patchConfigStarted_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Patch.Started );

            // update
            updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        void removeNotification( string siteurl, Guid? notificationId )
        {
            if ( notificationId.HasValue && StifelNotificationDao.ListExists( siteurl ) )
            {
                StifelNotificationDao dao = new StifelNotificationDao( siteurl );
                dao.Delete( notificationId.Value );
            }
        }

        /// <summary>
        /// Request has been fulfilled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void requestApprovedAndCompleted_ExecuteCode( object sender, EventArgs e )
        {
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, "Request completed." );

            string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.RequestCompleted, CurrentRequest.Id, CurrentRequest.UniqueId );
            string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.RequestCompleted, CurrentRequest.Id, CurrentRequest.UniqueId );

            // send email
            SPSendEmail spSendEmail = new SPSendEmail( );
            if ( CurrentRequest.Author.Email != null )
            {
                bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, new MailAddress( CurrentRequest.Author.Email ) );
                if ( !ok )
                    CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
            }

            CurrentRequest.OverallStatus = OverallStatus.Completed;

            updateRequest( CurrentRequest );
        }

        private void requestApproved_ExecuteCode( object sender, EventArgs e )
        {
            if ( CurrentRequest.AdvanceApprovalStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Approval.Approved );

                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.RequestAccepted, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.RequestAccepted, CurrentRequest.Id, CurrentRequest.UniqueId );

                // send email
                SPSendEmail spSendEmail = new SPSendEmail( );
                if ( CurrentRequest.Author.Email != null )
                {
                    bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, new MailAddress( CurrentRequest.Author.Email ) );
                    if ( !ok )
                        CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                }

                NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;

                // remove notification
                if ( notificationId.ApprovalNotificationId != null )
                    removeNotification( configuration.ApprovalSiteURLUrl, notificationId.ApprovalNotificationId );

                // clear notification
                notificationId.ApprovalNotificationId = null;
                CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );

                // set over all status
                CurrentRequest.OverallStatus = OverallStatus.Approved;

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        /// <summary>
        /// Request is completed, ie. the request has been submitted. 
        /// Set the request status to finalized. Log the activity.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void requestCompleted_ExecuteCode( object sender, EventArgs e )
        {
            sendRequestorNotification( );

            if ( CurrentRequest.AdvanceRequestStatus( ) )
            {
                // add audit log entry
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Requestor.Completed );
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Requestor.Finalized );

                // update
                updateRequestAndTriggerWorkflow( CurrentRequest );
            }
        }

        /// <summary>
        /// Request is finalized, ie. the request is ready to move to the next stage within the workflow. 
        /// Set the next appropriate status to move to next stage. Log the activity.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void requestRejectedAndCompleted_ExecuteCode( object sender, EventArgs e )
        {
            // TODO: CurrentRequest.OverallStatus = OverallStatus.Completed;
        }

        private void requestRejected_ExecuteCode( object sender, EventArgs e )
        {
            // add audit log entry
            CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Approval.Rejected );
            string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.RequestRejected, CurrentRequest.Id, CurrentRequest.UniqueId );
            string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.RequestRejected, CurrentRequest.Id, CurrentRequest.UniqueId );
            // send email
            SPSendEmail spSendEmail = new SPSendEmail( );
            if ( CurrentRequest.Author.Email != null )
            {
                bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, new MailAddress( CurrentRequest.Author.Email ) );
                if ( !ok )
                    CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
            }
            NotificationId notificationId = CurrentRequest.NotificationIdDeserialized;

            // remove notification
            if ( notificationId.ApprovalNotificationId != null )
                removeNotification( configuration.ApprovalSiteURLUrl, notificationId.ApprovalNotificationId );

            // clear notification
            notificationId.ApprovalNotificationId = null;
            CurrentRequest.NotificationId = CurrentRequest.SerializeNotificationId( notificationId );
            // set over all status
            CurrentRequest.OverallStatus = OverallStatus.Rejected;
            CurrentRequest.RequestCompleted = true;
            CurrentRequest.ApprovalStatus = ApprovalStatus.Finalized;
            // update
            updateRequest( CurrentRequest );
            //updateRequestAndTriggerWorkflow( CurrentRequest );
        }

        /// <summary>
        /// Request is started, ie. the request has been saved, but not submitted. 
        /// Send notification to requestor with link. Set request email date for tracking. Log the activity.
        /// Note: Process the first time only.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void requestStarted_ExecuteCode( object sender, EventArgs e )
        {
            bool update = sendRequestorNotification( );

            // update
            if ( update )
                updateRequestButNoTriggerWorkflow( CurrentRequest );
        }

        bool sendRequestorNotification( )
        {
            bool update = false;
            if ( !CurrentRequest.RequestorNotificationDate.HasValue )
            {
                // add audit log entry
                CurrentRequest.RequestorNotificationDate = DateTime.Now;
                CurrentRequest.ActivityAuditLog = ActivityAuditLog.AddEntry( CurrentRequest.ActivityAuditLog, CurrentUser.LoginName, Message.Requestor.Started );

                //
                string title = configuration.FormatNotificationTitle( StifelVirtualServerRequestConfiguration.Area.Requestor, CurrentRequest.Id, CurrentRequest.UniqueId );
                string notification = configuration.FormatNotification( StifelVirtualServerRequestConfiguration.Area.Requestor, CurrentRequest.Id, CurrentRequest.UniqueId );

                // send email
                SPSendEmail spSendEmail = new SPSendEmail( );
                bool ok = spSendEmail.SendEmail( CurrentWeb.Url, title, notification, new MailAddress( CurrentUser.Email, string.IsNullOrEmpty( CurrentUser.Name ) ? CurrentUser.LoginName : CurrentUser.Name ) );
                if ( !ok )
                    CustomLoggingService.LogWarning( CustomLoggingService.Area.General, Message.GeneralError.ERROR_SENDEMAIL( spSendEmail.InternalEmailSpecifics.OutboundMailServerAddress, spSendEmail.InternalEmailSpecifics.OutboundMailSenderAddress, spSendEmail.InternalEmailSpecifics.OutboundMailReplyToAddress ) );
                update = true;
            }
            return update;
        }

        void updateRequest( StifelVirtualServerRequest request )
        {
            StifelServerBuildDao dao = new StifelServerBuildDao( CurrentWeb.Url );
            dao.Update( CurrentRequest );
        }

        void updateRequestAndTriggerWorkflow( StifelVirtualServerRequest request )
        {
            request.Control = true;
            updateRequest( request );
        }

        void updateRequestButNoTriggerWorkflow( StifelVirtualServerRequest request )
        {
            request.Control = null;
            updateRequest( request );
        }

        #endregion Methods
    }
}